﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AppPressFramework;
using ApplicationClasses;

namespace Application
{
    public partial class PluginLogic
    {
        public static void OnClick(AppPress a, AdminMenusExtensionClass.ReportsFieldClass Reports) 
        {
            AuditReportClass.Redirect(a,null,null);
        }
        public static void Init(AppPress a, AdminMenusExtensionClass AdminMenus)
        {
            var isAdmin = ((AppLogic.AppSessionData)a.sessionData).isAdmin;
            if (!isAdmin)
            {
                AdminMenus.Reports.Hidden = FieldHiddenType.Hidden;
            }
        }

        public static void OnClick(AppPress a, AuditReportClass.ReportFieldClass Report) 
        {
            var query = @"
                Select Application_AuditType.AuditType,TableName,RowId,Time,Page,Change,TimeStamp
                From Application_Audit 
                Left Outer Join Application_AuditType On Application_AuditType.Id=Application_Audit.AuditType
                Where 1=1 ";
            if (Report.FormData.DatesFrom.val != null)
                query += "and Time>='" + Report.FormData.DatesFrom.val.Value.ToString(DAOBasic.DBDateFormat) + "'";
            if (Report.FormData.DatesTo.val != null)
                query += "and Time<='" + Report.FormData.DatesTo.val.Value.ToString(DAOBasic.DBDateFormat) + "'";
            a.ViewHTML(query, "Audit Report");
        }
    }
}
